//
//  CLDocFocusCell.m
//  chanlin
//
//  Created by shuhui on 15-7-1.
//  Copyright (c) 2015年 chanlin. All rights reserved.
//

#import "CLDocFocusCell.h"
#import "IFLabel2.h"
#import "UIView+Utils.h"

@interface CLDocFocusCell()
@property (nonatomic, strong) UIImageView *topFrameImg;
@property (nonatomic, strong) UIImageView *middleFrameImg;
@property (nonatomic, strong) UIImageView *bottomFrameImg;
@property (nonatomic, strong) UILabel *abstractLab;
@end
@implementation CLDocFocusCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self _createView];
    }
    return self;
}

-(void)_createView {
    
    self.topFrameImg = [[UIImageView alloc]init];
    [self.topFrameImg setImage:[UIImage imageNamed:@"topic_ abstract_frame_top.png"]];
    [self.contentView addSubview:self.topFrameImg];
    
    self.bottomFrameImg = [[UIImageView alloc]init];
    [self.bottomFrameImg setImage:[UIImage imageNamed:@"topic_ abstract_frame_bottom.png"]];
    [self.contentView addSubview:self.bottomFrameImg];
    
    
    self.abstractLab = [[UILabel alloc]init];
    self.abstractLab.backgroundColor = RGB(0xf8, 0xf8, 0xf8);
    self.abstractLab.font = [UIFont systemFontOfSize:16];
    self.abstractLab.textAlignment = NSTextAlignmentLeft;
    self.abstractLab.textColor = RGB(0x54, 0x54, 0x54);
    [self.contentView addSubview:self.abstractLab];
    
    
    self.message=[[IFLabel2 alloc] init];
    self.message.font=[UIFont systemFontOfSize:16];
    self.message.textAlignment=kCTTextAlignmentLeft;
    self.message.textColor=RGB(0x5b, 0x85, 0x9e);
    self.message.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    [self.contentView addSubview:self.message];
}

-(void)setText:(NSString *)text withTitle:(NSString *)title{
    
    CGFloat height = [IFLabel2 suggestHeightOfString:text withWidth:275.f font:[UIFont systemFontOfSize:16] lineSpace:0]+38;
    
    self.abstractLab.text = [NSString stringWithFormat:@" %@",_isStrNotNull(title)?title:@" 摘要"];
    
    self.topFrameImg.frame = CGRectMake(11, 18, GlobleWidth-22.f, 7.5);
    
    int count = (height-7.5-1.5-18)/6;
    for (int i = 0; i<count; i++) {
        self.middleFrameImg = [[UIImageView alloc]init];
        self.middleFrameImg.frame = CGRectMake(11, self.topFrameImg.frame.origin.y+7.5+i*6, GlobleWidth-22.f, 6);
        [self.middleFrameImg setImage:[UIImage imageNamed:@"topic_ abstract_frame_middle.png"]];
        [self.contentView addSubview:self.middleFrameImg];
    }
    
    self.bottomFrameImg.frame = CGRectMake(11, height-1.5, GlobleWidth-22.f, 1.5);
    
    UIFont *fnt = [UIFont systemFontOfSize:16.f];
    _abstractLab.font = fnt;
    // 根据字体得到NSString的尺寸
    CGSize size = [_abstractLab.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
    self.abstractLab.frame = CGRectMake(25, 11, size.width+10, 16);
    self.message.frame=CGRectMake(11+12, 15+18, GlobleWidth-22.f-24, height);
    self.message.text=text;
}


@end
